'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 处理奖励重复
 * @author sundbcn@gmail.com (sun debing)
 */

var _ = require('lodash');

/**
 * 处理奖励
 */
exports.dealRewardList = function (reward) {
    var reward_list = _.union(_.uniq(reward, 'reward'), _.uniq(reward, 'reward_type'));
    for (var i = reward_list.length - 1; i >= 0; i--) {
        var reward_item = reward_list[i];
        reward_item.reward_num = _dect_same_reward(reward_item, reward);
    }
    return reward_list;
};

var _dect_same_reward = function (reward_item, reward_list) {
    var dect_reward = reward_item;
    var reward_num = 0;
    _.each(reward_list, function (reward) {
        if (reward.reward == dect_reward.reward && reward.reward_type == dect_reward.reward_type) {
            reward_num += reward.reward_num;
        }
    });
    return reward_num;
};
